<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of EventoController
 *
 * @author Alessandro
 */
class DemoController extends CustomController {

 
    /**
     * Action principal do controller, que apresenta a interface basica do sistema
     */
    public function actionIndex()
    {
        echo "controller de demosntração";
    }


    public function actionCurrying()
    {

        function curry($func, $aridade) { 
            return create_function('', " 
                \$args = func_get_args(); 
                if(count(\$args) >= $aridade) 
                    return call_user_func_array('$func', \$args); 
                \$args = var_export(\$args, 1); 
                return create_function('',' 
                    \$a = func_get_args(); 
                    \$z = ' . \$args . '; 
                    \$a = array_merge(\$z,\$a); 
                    return call_user_func_array(\'$func\', \$a); 
                '); 
            "); 
        } 

        function soma($a,$b)
        {
            return $a+$b;
        }

        $temp=curry("soma",2);

        $inc=$temp(1);

        $dec=$temp(-1);

        echo $inc(3)." ".$dec(10);

    }

    public function actionMap()
    {

        function quadrado($a)
        {
            return $a*$a;
        }

        $nrs=range(0, 10);

        $new= array_map("quadrado", $nrs);

        echo var_export($new);
    }

 
    public function actionReduce()
    {
        function sum($a,$b)
        {
            return $a+$b;
        }

        $nrs=range(2,5);

        $new =array_reduce($nrs, create_function('$a,$b', 'return $a+$b;'),1);

        echo var_export($new);

    }

}
